package com.bwie.controller;

import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.extra.mail.MailUtil;
import com.bwie.poi.ExcelUtil;
import com.bwie.poi.ExceptionUtil;
import com.bwie.pojo.Prod;
import com.bwie.service.ProdService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.kafka.common.protocol.types.Field;
import org.checkerframework.checker.tainting.qual.PolyTainted;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.metadata.PostgresTableMetaDataProvider;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author:杨珂
 * @CreateTime: 2025-03-26
 */

@RestController
@RequestMapping("/prod/index")
@Api(tags = "商品管理")
public class IndexController {

    @Autowired
    private ProdService prodService;

    /**
     * 根据类型获取字典列表
     *
     * @param id
     * @return
     */
    @PostMapping("/getDictList/{id}")
    public R getDictList(@PathVariable("id") Integer id) {
        return prodService.getDictList(id);
    }


    @PostMapping("/getProdList")
    public R getProdList(@RequestBody PageInfoVo pageInfoVo) {
        return prodService.getProdList(pageInfoVo);
    }


    /**
     * 分页从Es中获取商品列表
     *
     * @param pageInfoVo
     * @return
     */
    @PostMapping("/getProdListFromEs")
    public R getProdListFromEs(@RequestBody PageInfoVo pageInfoVo) {
        return prodService.getProdListFromEs(pageInfoVo);
    }


    /**
     * @param prod:
     * @return R
     * @author :杨珂
     * @description TODO
     * @date 2025/4/7 19:39
     */
    @PostMapping("/addProd")
    public R addProd(@RequestBody Prod prod) {
        return prodService.addProd(prod);
    }


    /**
     * @param :
     * @return void
     * @author :杨珂
     * @description 导出所有商品
     * @date 2025/4/7 19:39
     */
    @ApiOperation("导出")
    @GetMapping("/exportProdExcel")
    public void exportProdExcel() {
        prodService.exportProdExcel();
    }


    /**
     * @param ids:
     * @return void
     * @author :杨珂
     * @description 选中导出
     * @date 2025/4/8 9:58
     */
    @ApiOperation("选中导出")
    @GetMapping("/exportProdCheck{ids}")
    public void exportProdCheck(@PathVariable("ids") String ids) {
        prodService.exportProdCheck(ids);
    }

    /**
     * @param file:
     * @return R
     * @author :杨珂
     * @description 导入商品列表
     * @date 2025/4/8 13:13
     */

    @ApiOperation("导入")
    @PostMapping("/importProdExcel")
    public R importProdExcel(@RequestPart("file") MultipartFile file) {
        return prodService.importProdExcel(file);
    }


}
